$(function () {
	console.log($(".creditor-list"))
    var itemIndex = 0;
    var tabLoadEndArray = [false, false,false];
    var tabScroolTopArray = [0, 0];
    var pageindex = 0;
    var pagesize = 10;
    var memberstatus = 0;
    var fIndex = 0;
    var sIndex = 0;
    var tIndex = 0;
    var pagerow;
    // load(memberstatus, itemIndex, pageindex, pagesize);
    //dropload
    var dropload = $('#wrapper').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
            domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData: '<div class="dropload-noData">已加载完</div>'
        },
        loadDownFn: function (me) {
            if (tabLoadEndArray[itemIndex]) {
                me.resetload();
                me.lock();
                me.noData();
                me.resetload();
                return;
            }

            if (itemIndex == 0) {
                fIndex++
                var sval = {
                    //   FinancialOrderID:showDetail(),
                    ordertype:'-10',
                    pageindex: fIndex,
                    pagerows: pagesize
                };
            }else if (itemIndex == 1) {
				sIndex++;
                var sval = {
					//   FinancialOrderID:showDetail(),
					ordertype:'1',
                    pageindex: sIndex,
                    pagesize: pagesize
                };
            } else {
                tIndex++;
                var sval = {
					//   FinancialOrderID:showDetail(),
					ordertype:'2',
                    pageindex: tIndex,
                    pagesize: pagesize
                };
            }
            function doCallBack(ret) {
                console.log(ret)
                if (ret.retcode == 0) {
                    var Data = Base64.decode(ret.data);
                    console.log(Data)
                    $(".wrap").show();
                    if (ret.data) {
                        console.log('itemIndex--' + itemIndex)
                        var result = JSON.parse(Data);
                        console.log(result)
                        if (result.allrows == 0) {
                            me.lock();
                            me.noData();
                            tabLoadEndArray[itemIndex] = true;
                            me.resetload();
                            $('.dropload-down').hide();
                        } else {
                            $('.dropload-down').show();
                        }
                        var flagBtn = $(".creditor-list").eq(itemIndex).attr('btn');
                        if (result.allrows == 0 && flagBtn == "false") {
                            noRecord($(".creditor-list").eq(itemIndex));
                            $('.dropload-down').hide();
                        } else {
                            $('.dropload-down').show();
                        }
                        if (result.allrows < 5) {
                            me.lock();
                            me.noData();
                            tabLoadEndArray[itemIndex] = true;
                            me.resetload();
                            $('.dropload-down').hide();
                        } else {
                            $('.dropload-down').show();
                        }

                        if (result.allrows > 0) {
                            // //将数据填充到模板里
                            allPages = result.allpages;
                            if (result.list.length > 0) {
                                var html = templateDate(result);
                                console.log(html)
                                console.log($(".creditor-list").eq(itemIndex))
                                $(".creditor-list").eq(itemIndex).append(html);
                            }
                            if (result.list.length < pagesize) {
                                me.lock();
                                me.noData();
                                tabLoadEndArray[itemIndex] = true;
                            }
                            if (allPages == pageindex) {

                                me.lock();
                                me.noData();
                                tabLoadEndArray[itemIndex] = true;
                            }
                            me.resetload();


                        }


                    } else {
                        noRecord($(".creditor-list").eq(itemIndex));
                        $('.dropload-down').hide();
                    }
                }else{
                    noRecord($(".creditor-list").eq(itemIndex));
                    $('.dropload-down').hide();
                }
				
                


            }

            jAjax("account.getbill", doCallBack, sval);
        },
        threshold: 0
	});

	function templateDate(data) {
		var htmlfinborListData = template("allList", data);
		return htmlfinborListData;
	}
	
    // ==================tab切换=====
    //tab切换
    var experienceFlag = true;
    $(".tab-bar ul li").click(function () {
       
        tabScroolTopArray[itemIndex] = $(window).scrollTop();
        itemIndex = $(".tab-bar ul li").index($(this));                                                   
        var index = $(this).index();
        var $this = $(this);
        $(".tab-bar ul li").eq(index).addClass("current").siblings().removeClass("current");
		$('.data-content').eq(itemIndex).show().siblings('.data-content').hide();
        curPage = index + 1;
        if (!tabLoadEndArray[itemIndex]) {
            dropload.unlock();
            dropload.noData(false);
        } else {
            dropload.lock('down');
            dropload.noData();
            // if ($('#list li').length <= 5) {
            //     $('.dropload-down').hide();
            // } else {
            //     $('.dropload-down').show();
            // }
        }
        dropload.resetload();
    })

});

